import {doGet, doGetDirect, doPostJson, doPostUrlEncoding, Result} from "./generic";
import {Urls} from "./ApiUrl";


export class CreateGameReq {
  playerCount: number

  constructor(playerCount: number) {
    this.playerCount = playerCount;
  }

}

export class CreateGameResp {
  gameId: number
  houseCode: number

  constructor(gameId: number, houseCode: number) {
    this.gameId = gameId;
    this.houseCode = houseCode;
  }

}

export class JoinGameReq {
  houseCode: number

  constructor(houseCode: number) {
    this.houseCode = houseCode;
  }
}

export class JoinGameResp {
  players: Array<String>

  constructor(players: Array<String>) {
    this.players = players;
  }
}



export class PlayerInHouseResp {
  players: Array<string>


  constructor(players: Array<string>) {
    this.players = players;
  }
}

export const GameApi = {

  Create: (req: CreateGameReq): Promise<Result<CreateGameResp>> => {
    return doPostJson(Urls.game.create, req)
  },
  Join: (req: JoinGameReq): Promise<Result<JoinGameResp>> => {
    return doPostJson(Urls.game.join, req)
  },
  getGameId: (): Promise<Result<number>> => {
    return doGetDirect(Urls.game.getGameId)
  },

  GetPlayerInHouse: (): Promise<Result<PlayerInHouseResp>> => {
    return doGetDirect(Urls.game.getPlayerInHouse)
  },

}
